package top.glkj.hms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.glkj.hms.service.IndexService;
import top.glkj.hms.utils.Result;
import top.glkj.hms.utils.ResultFactory;

import javax.annotation.security.PermitAll;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2020/10/31 23:52
 * 后端首页定制
 */
@Api(tags = "首页")
@RestController
public class IndexController {
    private final IndexService indexService;

    @Autowired
    public IndexController(IndexService indexService) {
        this.indexService = indexService;
    }

    @PermitAll
    @GetMapping("/index")
    public Result getIndex() {
        return ResultFactory.SUCCESS;
    }

    @PermitAll
    @PostMapping("/index")
    public Result postIndex() {
        return ResultFactory.EXCEPTION;
    }

    @PermitAll
    @PutMapping("/index")
    public Result putIndex() {
        return ResultFactory.ERROR;
    }

    @PermitAll
    @DeleteMapping("/index")
    public Result deleteIndex() {
        return ResultFactory.NOTFOUND;
    }

    @RequestMapping("/getMessage")
    public Result getMessage() {
        return ResultFactory.isSuccess(11);
    }
    //@PreAuthorize("hasRole('admin')")
    //@PostMapping
    //public Result getMenu(){
    //    User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    //    return indexService.getMenu(user);
    //}

    @ApiOperation("获取earChat数据")
    @GetMapping("/getData")
    public Result getData(){return indexService.getData();}
}
